<template>
	<view class="root">
		<template v-if="needAgreements">
			<view class="flex items-center">
				<checkbox-group @change="setAgree">
					<label class="checkbox-box">
						<checkbox :checked="isAgree" style="transform: scale(0.7);margin-right: -2px;" />
						<text class="text">同意</text>
					</label>
				</checkbox-group>
				<view class="flex">
					<!--  #ifdef H5 -->
					<u-link :href="agreements[0].url" :text="agreements[0].title" fontSize="12"></u-link>
					<!--  #endif -->
					<!--  #ifndef H5 -->
					<text class="text agreement" @click="seeInfo(`/pages/user/agreements/agreements?url=${agreements[0].url}`)">{{agreements[0].title}}</text>
					<!--  #endif -->
					<!-- <text class="text"> 和 </text> -->
					<!-- <text class="text agreement">{{agreements[1].title}}</text> -->
				</view>
			</view>
		</template>
		<!-- 弹出式 -->
		<u-modal :show="modal.show" :title="modal.title" showCancelButton @confirm="confirmModal" @cancel="closeModal">
			<view class="flex">
				<!--  #ifdef H5 -->
				<u-link :href="agreements[0].url" :text="agreements[0].title" fontSize="12"></u-link>
				<!--  #endif -->
				<!--  #ifndef H5 -->
				<text class="text agreement" @click="seeInfo(`/pages/user/agreements/agreements?url=${agreements[0].url}`)">{{agreements[0].title}}</text>
				<!--  #endif -->
				<!-- <text class="text"> 和 </text> -->
				<!-- <text class="text agreement">{{agreements[1].title}}</text> -->
			</view>
		</u-modal>
	</view>
</template>

<script>
	let retryFun = () => console.log('为定义')
	export default {
		name: "agreements",
		props: {
			value: {
				type: Boolean,
				default () {
					return false
				}
			},
			needAgreements: {
				type: Boolean,
				default () {
					return false
				}
			},
		},
		data() {
			return {
				e:null,
				isAgree:this.value,
				agreements:[
					{
						url: 'https://middtest.qstamper.com:9099/tips/用户须知.html',
						title: "用户须知"
					}
				],
				
				modal:{
					show:false,
					title:'请先阅读并同意'
				}
			};
		},
		methods: {
			seeInfo(url){
				
				uni.navigateTo({
					url: url,
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			confirmModal() {
				this.isAgree = true
				this.$emit('input', this.isAgree);
				retryFun(this.e)
				this.closeModal()
			},
			popup(Fun,e) {
				this.e = e
				this.$nextTick(() => {
					if (Fun) {
						retryFun = Fun
					}
					this.modal.show = true
				})
			},
			navigateTo({
				url,
				title
			}) {
				uni.navigateTo({
					url: '/uni_modules/uni-id-pages/pages/common/webview/webview?url=' + url + '&title=' + title,
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			setAgree(e) {
				this.isAgree = !this.isAgree
				this.$emit('input', this.isAgree);
			},
			closeModal() {
				this.modal.show = false
			}
		},

	}
</script>

<style lang="scss" scoped>
	.root {
		font-size: 12px;
		color: #8a8f8b;
	}
	.text {
		line-height: 26px;
	}
	.agreement {
		color: #409EFF;
		cursor: pointer;
	}
	.checkbox-box ::v-deep .uni-checkbox-input {
		border-radius: 100%;
	}
	.checkbox-box ::v-deep .uni-checkbox-input.uni-checkbox-input-checked {
		border-color: $uni-color-primary;
		color: #FFFFFF !important;
		background-color: $uni-color-primary;
	}
</style>